from django.conf import settings
from django.http import HttpResponse
from django.utils.encoding import smart_str, force_unicode

def textilePreview(request):
    value = request.POST['data']

    try:
        import textile
    except ImportError:
        if settings.DEBUG:
            raise template.TemplateSyntaxError, "Error in {% textile %} filter: The Python textile library isn't installed."
    else: 
        value = textile.textile(smart_str(value), encoding='utf-8', output='utf-8')

    return HttpResponse(force_unicode(value))
